#define _CRT_SECURE_NO_WARNINGS 1
#include<list>
#include<iostream>
using namespace std;



int main()
{
	list<int> lt;
	lt.push_back(1);
	lt.emplace_back(2);
	lt.emplace_back(3);
	lt.emplace_back(4);
	lt.emplace_back(5);

	list<int> lt2;
	lt2.emplace_back(2);
	lt2.emplace_back(3);
	lt2.emplace_back(4);
	lt2.emplace_back(5);


	list<int>::iterator it = lt.begin();
	list<int>::iterator it2 = lt2.begin();

	//auto it = lt.begin();
	/*int n = 0;
	cin >> n;
	int* p= find(lt.begin(), lt.end(), 3);*/
	/*while (it != lt.end())
	{
		cout << *it <<"";
		++it;
	}*/
	/*int k = 0;
	cin >> k;
	while (k--)
	{
		++it;
	}*/
	/*it = find(lt.begin(), lt.end(), 2);
	if(it!=lt.end())
		lt.erase(it);*/
	//greater<int> gt;
	//lt.sort(gt);	
	//lt.sort(greater<int>());
	//lt.merge(lt2);
	

	for (auto e:lt)
	{
		cout << e << " ";
	}
	
	cout << endl;

	//lt.unique();
	//lt.swap(lt2);
	//lt.remove(2);
	/*++it;
	++it;
	lt.splice(it, lt2);*/

	int n = 0;
	cin >> n;
	it2 = find(lt2.begin(), lt2.end(), n);

	if (it != lt.end())
	{
		//lt.splice(lt.begin(), lt, it, lt.end());
		lt.splice(it, lt2,it2,lt2.end());
	}

	for (auto e : lt)
	{
		cout << e << " ";
	}
	
	cout << endl;
	return 0;
}